package com.ucar.train.service.xumingzhi.Process;

import com.ucar.train.service.xumingzhi.ResultUtil.Result;
import com.ucar.train.service.xumingzhi.ResultUtil.ResultUtil;


import java.util.concurrent.*;

/**
 * Desciption:
 * todo 加机油
 *
 * @Author: XuMingZhi.
 * Creation time: 2019/8/22 8:36:00.
 * © Copyright 2013-2019, UCar.
 */
public class RefuelingOil extends ProcessTemplate implements Callable<Result> {

    @Override
    public Result maintain() {
        try {
            FutureTask<Result> futureTask = new FutureTask<>(new RefuelingOil());
            Thread thread = new Thread(futureTask);
            thread.start();
            return futureTask.get(3, TimeUnit.SECONDS);//设置超时时间
        } catch (InterruptedException e) {
            return ResultUtil.BADREQUEST("加机油，未知错误");
        } catch (ExecutionException e) {
            return ResultUtil.BADREQUEST("加机油，未知错误");
        } catch (TimeoutException e) {
            return ResultUtil.TIMEOUT("正在加机油,超时");
        }
    }

    @Override
    public Result call() throws InterruptedException {

         Thread.sleep(10000);
       // throw new InterruptedException();

         return ResultUtil.SUCCESS("加机油成功！");
    }
}
